package 设计模式.proxy.cglib;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author Jim
 * @date 10:27 下午 2022/4/1
 * @description
 * @email:huwmz04153277@126.com
 */
public class MyMethodInterceptor  implements MethodInterceptor {

    /**
     * sub：cglib生成的代理对象
     * method：被代理对象方法
     * objects：方法入参
     * methodProxy: 代理方法
     */
    @Override
    public Object intercept(Object sub, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("======插入前置通知======");
        //sub代理对象
        Object object = methodProxy.invokeSuper(sub, objects);

        System.out.println("======插入后者通知======");
        return object;

    }
}
